package com.qianyu.project.web.controller.base;

import cn.hutool.core.lang.tree.TreeUtil;
import com.qianyu.project.core.context.user.FlowUserProvider;
import com.qianyu.project.service.ISystemAuthorityService;
import com.qianyu.project.service.ISystemUserService;
import com.qianyu.project.utils.AuthorityUtil;
import com.qianyu.project.utils.Result;
import com.qianyu.project.utils.ResultTool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author gs
 * @date create in 2020/12/24 16:45
 */
@RestController
@RequestMapping("/authorities")
public class SystemAuthorityController {

    @Autowired
    private ISystemAuthorityService systemAuthorityService;
    @Autowired
    private FlowUserProvider flowUserProvider;
    @Autowired
    private ISystemUserService systemUserService;

    @GetMapping("/menu")
    public Result menu() {
        return ResultTool.success(
                AuthorityUtil.build(
                        systemAuthorityService,
                        systemUserService,
                        flowUserProvider
                )
        );
    }

    @GetMapping
    public Result list(){
        return ResultTool.success(systemAuthorityService.listAndFlow());
    }

    @GetMapping("{moduleid}")
    public Result getUpdateauthority(@PathVariable Integer moduleid){
        return ResultTool.success(systemAuthorityService.getUpdateauthority(moduleid));
    }
}
